package com.juneng.common;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * 分页数据封装类
 */
@Data
@NoArgsConstructor
public class CommonPage<T> {
    private Integer pageNum;//当前页
    private Integer pageSize;//每页显示条数
    private Integer totalPage;//总页数
    private Integer total;//总条数
    private List<T> list;//当前页数据

    /**
     * 获取总条数
     * @param pageNum
     * @param pageSize
     * @param total
     * @param list
     */
    public CommonPage(Integer pageNum, Integer pageSize, Integer total, List<T> list) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.total = total;
        this.totalPage = (this.total + this.pageSize - 1) / this.pageSize;
        this.list = list;
    }

    /**
     * 获取总页数
     *
     * @param count    总记录数
     * @param pageSize 每页显示条数
     * @return
     */
    public static Integer getTotalPage(Integer count, Integer pageSize) {
        return count % pageSize > 0 ? count / pageSize + 1 : count / pageSize;
    }
}
